package com.gongpingjialoan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.data.OrderRecord;
import com.gongpingjialoan.utility.TimeUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/5/19.
 */
public class LoanRecordAdapter extends BaseAdapter {

    private List<OrderRecord.DataBean> mRecordsBeans;

    private Context mContext;

    private LayoutInflater mLayoutInflater;

    public LoanRecordAdapter(List<OrderRecord.DataBean> recordsBeans, Context context) {
        mRecordsBeans = recordsBeans;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }

    public void setData(List<OrderRecord.DataBean> recordsBeans) {
        this.mRecordsBeans = recordsBeans;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mRecordsBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return mRecordsBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.loan_record_item, null);
            holder = new ViewHolder();
            holder.loan_num_tv = (TextView) convertView.findViewById(R.id.loan_num_tv);
            holder.status_tv = (TextView) convertView.findViewById(R.id.status_tv);
            holder.money_tv = (TextView) convertView.findViewById(R.id.money_tv);
            holder.time_tv = (TextView) convertView.findViewById(R.id.time_tv);
            convertView.setTag(R.id.tag_first, holder);
        } else {
            holder = (ViewHolder) convertView.getTag(R.id.tag_first);
        }
        OrderRecord.DataBean source = mRecordsBeans.get(position);
        convertView.setTag(R.id.tag_second, source);
        if (source != null) {
            holder.loan_num_tv.setText(source.getOrder_no());
            holder.status_tv.setText(source.getStatus_name()+"");
            holder.money_tv.setText(Float.parseFloat(source.getRequestValue())/10000+"万");
            holder.time_tv.setText(TimeUtils.timeMonthHourMinFormat(Math.round(Double.parseDouble(source.getUpdated_at())*1000)));
        }
        return convertView;
    }


    public static class ViewHolder {

        public TextView loan_num_tv;

        public TextView status_tv;

        public TextView money_tv;

        public TextView time_tv;

    }
}

